<?php

require '../vendor/autoload.php';
date_default_timezone_set('PRC');
use Monolog\Logger;
use Monolog\Handler\StdoutHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\ErrorLogHandler;
// Create the logger
$logger = new Logger('my_logger');
  
$logger->pushHandler(new StreamHandler(__DIR__.'/my_app.log', Logger::INFO));

$logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::ERROR, false));

$logger->pushHandler(new StdoutHandler());

$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('106.13.63.203:9092');
$config->setBrokerVersion('1.0.0');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer(
    function() {
        return [
            [
                'topic' => 'news',
                'value' => time()." hello world"
            ],
        ];
    }
);

$producer->setLogger($logger);
$producer->success(function($result) {
    echo 'success\n';
	var_dump($result);
});
$producer->error(function($errorCode) {
    echo "fail";
		var_dump($errorCode);
});
$producer->send(true);